<?php

/**
 * This is the model class for table "{{helpinfo}}".
 *
 * The followings are the available columns in table '{{helpinfo}}':
 * @property integer $id
 * @property string $userid
 * @property string $helpdate
 * @property string $helptype
 * @property string $helplevel
 * @property string $helpclass
 * @property string $indate
 * @property string $writer
 * @property integer $tmpi1
 * @property integer $tmpi2
 * @property integer $tmpi3
 * @property string $tmps1
 * @property string $tmps2
 * @property string $tmps3
 */
class Helpinfo extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{helpinfo}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('userid, helptype, helplevel, helpclass', 'required'),
			array('tmpi1, tmpi2, tmpi3', 'numerical', 'integerOnly'=>true),
			array('userid, helptype, helplevel, helpclass, writer', 'length', 'max'=>20),
			array('tmps1, tmps2, tmps3', 'length', 'max'=>50),
			array('helpdate, indate', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, userid, helpdate, helptype, helplevel, helpclass, indate, writer, tmpi1, tmpi2, tmpi3, tmps1, tmps2, tmps3', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
            //'hzxx'=>array(self::HAS_ONE,'Hzxx','','on'=>'userID=userid'),
            'hzxx'=>array(self::BELONGS_TO,'Hzxx','userid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '序号',
			'userid' => '救助对象',
			'helpdate' => '救助时间',
			'helptype' => '救助类别',
			'helplevel' => '救助级别',
			'helpclass' => '救助方式',
			'indate' => '添加时间',
			'writer' => '录入人',
			'tmpi1' => 'Tmpi1',
			'tmpi2' => 'Tmpi2',
			'tmpi3' => 'Tmpi3',
			'tmps1' => 'Tmps1',
			'tmps2' => 'Tmps2',
			'tmps3' => 'Tmps3',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('userid',$this->userid,true);
		$criteria->compare('helpdate',$this->helpdate,true);
		$criteria->compare('helptype',$this->helptype,true);
		$criteria->compare('helplevel',$this->helplevel,true);
		$criteria->compare('helpclass',$this->helpclass,true);
		$criteria->compare('indate',$this->indate,true);
		$criteria->compare('writer',$this->writer,true);
		$criteria->compare('tmpi1',$this->tmpi1);
		$criteria->compare('tmpi2',$this->tmpi2);
		$criteria->compare('tmpi3',$this->tmpi3);
		$criteria->compare('tmps1',$this->tmps1,true);
		$criteria->compare('tmps2',$this->tmps2,true);
		$criteria->compare('tmps3',$this->tmps3,true);
        /**
 * $criteria->join = 'LEFT JOIN {{hzxx}} ON {{hzxx}}.userid=id';
 *         
 *         $criteria->addSearchCondition('{{hzxx}}.region3',YII::app()->user->uuid);
 *         $criteria->addSearchCondition('{{hzxx}}.region4',YII::app()->user->facebook);
 *         $criteria->addSearchCondition('{{hzxx}}.region5',YII::app()->user->twitter);
 */
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Helpinfo the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
